package com.gitee.occo.sso.user.controller;

import java.time.Duration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gitee.occo.sso.user.entity.User;
import com.gitee.occo.sso.user.service.UserService;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/user")
public class UserController {

	@Autowired
	UserService userService;
	
	@GetMapping("/findById/{id}")
	public Mono<User> getUserById(@PathVariable("id")Long id){
		return userService.findById(id);
	}
	
	@GetMapping("/findByUsername")
	public Mono<User> findByUsername(String username){
		return userService.findByUsername(username);
	}
	
	@GetMapping(value="/findByUsernameLike" ,produces = MediaType.APPLICATION_STREAM_JSON_VALUE)
	public Flux<User> getByUsername(String username){
		return userService.findByUsernameLike(username+"%").delayElements(Duration.ofSeconds(2));
	}
}
